{extend name="common/layout" /}

{block name="title"}商品{if !empty($id)}修改{else/}添加{/if}{/block}
{block name="content"}
<div id="content">

    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right">
                <button type="submit" form="form-create" data-toggle="tooltip" title="保存" class="btn btn-primary">
                    <i class="fa fa-save"></i>
                </button>
                <a href="{:url('index')}" data-toggle="tooltip" title="取消" class="btn btn-default">
                    <i class="fa fa-reply"></i>
                </a>
            </div>
            <h1>商品{if !empty($id)}修改{else/}添加{/if}</h1>
            <ul class="breadcrumb">
                <li>
                    <a href="/back/site/index.html">首页</a>
                </li>
                <li>
                    <a href="/back/brand/index.html">商品</a>
                </li>
            </ul>
        </div>
    </div>
    <div class="container-fluid">
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <i class="fa fa-pencil"></i>
                    商品{if !empty($id)}修改{else/}添加{/if}
                </h3>
            </div>
            <div class="panel-body">
                <form action="{:url('set')}" method="post" enctype="multipart/form-data" id="form-create"
                      class="form-horizontal">
                    {if !empty($id)}<input type="hidden" value="{$id}" name="id"/>{/if}

                    <ul class="nav nav-tabs">
                        <li class="active">
                            <a href="#tab-general" data-toggle="tab">基本信息</a>
                        </li>
                        <li>
                            <a href="#tab-extra" data-toggle="tab">扩展信息</a>
                        </li>
                        <li>
                            <a href="#tab-desc" data-toggle="tab">描述内容</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab-general">

                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-title">名称</label>
                                <div class="col-sm-10">
                                    <input type="text" name="title" value="{$info.title|default=''}" placeholder="名称"
                                           id="input-title" class="form-control"/>
                                    {present name="msg.title"}
                                    <label class="text-danger" id="input-title-error"
                                           for="input-title">{$msg.title}</label>
                                    {/present}

                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label" for="input-upc">条码</label>
                                <div class="col-sm-10">
                                    <input type="text" name="upc" value="{$info.upc|default=''}" placeholder="条码"
                                           id="input-upc" class="form-control"/>
                                    {present name="msg.upc"}
                                    <label class="text-danger" id="input-upc-error" for="input-upc">{$msg.upc}</label>
                                    {/present}

                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-image">缩略图</label>
                                <div class="col-sm-10">
                                    <!--<input type="text" name="image" value="{$info.image|default=''}" placeholder="缩略图"-->
                                           <!--id="input-image" class="form-control"/>-->
                                        <span class="btn btn-success fileinput-button">
                                            <i class="glyphicon glyphicon-plus"></i>
                                            <span>选择主图像</span>
                                            <input type="file" id="fileupload" name="file">
                                        </span>
                                    <input type="hidden" name="image" value="{$info.image|default=''}" id="input-image" class="form-control">
                                    <input type="hidden" name="image_thumb" value="{$info.image_thumb|default=''}" id="input-image_thumb" class="form-control">
                                    <br><label for="" class="" style="display:none;" id="label-file-error"></label>

                                    {present name="msg.image"}
                                    <label class="text-danger" id="input-image-error"
                                           for="input-image">{$msg.image}</label>
                                    {/present}

                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-inventory">库存</label>
                                <div class="col-sm-3 text-left">
                                    <input type="text" name="inventory" value="{$info.inventory|default=''}"
                                           placeholder="库存"
                                           id="input-inventory" class="form-control "/>
                                    {present name="msg.inventory"}
                                    <label class="text-danger" id="input-inventory-error" for="input-inventory">{$msg.inventory}</label>
                                    {/present}
                                </div>
                                <div class="col-sm-7">
                                    <select name="unit_id" id="" class="form-control">
                                        <option>无选择</option>

                                        {volist name="unit_list" id="unit"}
                                        <option value="{$unit.id}" {if !empty($info)
                                                &&$info.unit_id==$unit.id}selected{/if}>{$unit.title}
                                        </option>
                                        {/volist}
                                    </select>
                                </div>


                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-mininum">最小起售</label>
                                <div class="col-sm-10">
                                    <input type="text" name="mininum" value="{$info.mininum|default=''}"
                                           placeholder="最小起售"
                                           id="input-mininum" class="form-control"/>
                                    {present name="msg.mininum"}
                                    <label class="text-danger" id="input-mininum-error" for="input-mininum">{$msg.mininum}</label>
                                    {/present}

                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-price">价格</label>
                                <div class="col-sm-10">
                                    <input type="text" name="price" value="{$info.price|default=''}" placeholder="价格"
                                           id="input-price" class="form-control"/>
                                    {present name="msg.price"}
                                    <label class="text-danger" id="input-price-error"
                                           for="input-price">{$msg.price}</label>
                                    {/present}

                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-price_orign">原价</label>
                                <div class="col-sm-10">
                                    <input type="text" name="price_orign" value="{$info.price_orign|default=''}"
                                           placeholder="原价"
                                           id="input-price_orign" class="form-control"/>
                                    {present name="msg.price_orign"}
                                    <label class="text-danger" id="input-price_orign-error" for="input-price_orign">{$msg.price_orign}</label>
                                    {/present}

                                </div>
                            </div>


                        </div>
                        <div class="tab-pane" id="tab-extra">

                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="">配送支持</label>
                                <div class="col-sm-10">

                                    {if condition="empty($id)||$info.is_shopping=='可配送'"}
                                    <label for="input-is_shopping" class="radio-inline">
                                        <input type="radio" name="is_shopping" value="1" id="input-is_shopping"
                                               checked/> 支持
                                    </label>
                                    <label for="input-is_shopping2" class="radio-inline"><input type="radio"
                                                                                                name="is_shopping"
                                                                                                value="0"
                                                                                                id="input-is_shopping2"
                                                                                                class=""/> 不支持</label>
                                    {else/}
                                    <label for="input-is_shopping" class="radio-inline">
                                        <input type="radio" name="is_shopping" value="1" id="input-is_shopping"/> 支持
                                    </label>
                                    <label for="input-is_shopping2" class="radio-inline"><input type="radio"
                                                                                                name="is_shopping"
                                                                                                value="0"
                                                                                                id="input-is_shopping2"
                                                                                                class="" checked/>
                                        不支持</label>

                                    {/if}
                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-date_avaliable">起送时间</label>
                                <div class="col-sm-10">
                                    <input type="text" name="date_avaliable" value="{$info.date_avaliable|default=''}"
                                           placeholder="起送时间" id="input-date_avaliable"
                                           class="form-control bootstrap-datetimepicker-widget"/>
                                    {present name="msg.date_avaliable"}
                                    <label class="text-danger" id="input-date_avaliable-error"
                                           for="input-date_avaliable">{$msg.date_avaliable}</label>
                                    {/present}

                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label">状态</label>
                                <div class="col-sm-10">
                                    <select name="status" class="form-control">
                                        {if condition="empty($id)||$info.status=='上架中'"}
                                        <option value="1" selected>上架</option>
                                        <option value="0" >下架</option>
                                        {else/}
                                        <option value="1">上架</option>
                                        <option value="0" selected>下架</option>
                                        {/if}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-brand_id">品牌</label>
                                <div class="col-sm-10">
                                    <select name="brand_id" id="input-brand_id" class="form-control">
                                        <option>未选择</option>
                                        {volist name="brand_list" id="brand"}
                                        <option value="{$brand.id}" {if $brand.id==$info.brand_id}selected{/if}>{$brand.title}</option>
                                        {/volist}

                                    </select>

                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-category_id">类别</label>
                                <div class="col-sm-10">
                                    <select name="category_id" id="input-category_id" class="form-control">
                                        {volist name="category_list" id="category"}
                                        <option value="{$category.id}" {if $category.id==$info.category_id}selected{/if}>{:str_repeat("&nbsp;",$category.leavel*4)}{$category.title}</option>
                                        {/volist}

                                    </select>

                                </div>
                            </div>
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-sort">排序</label>
                                <div class="col-sm-10">
                                    <input type="text" name="sort" value="{$info.sort|default=''}" placeholder="排序"
                                           id="input-sort" class="form-control"/>
                                    {present name="msg.sort"}
                                    <label class="text-danger" id="input-sort-error"
                                           for="input-sort">{$msg.sort}</label>
                                    {/present}

                                </div>
                            </div>
                        </div>
                        <div class="tab-pane" id="tab-desc">
                            <div class="form-group required">
                                <label class="col-sm-2 control-label" for="input-description">描述</label>
                                <div class="col-sm-10">
                                    <textarea name="description" id="input-description" class="form-control">{$info.description|default=''}</textarea>
                                </div>

                            </div>

                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>






<script type="text/javascript">
    $(function () {
        //时间插件
        $('.bootstrap-datetimepicker-widget').datetimepicker({
            format: 'YYYY-MM-DD HH:mm',
            todayHighlight: 1,
            autoclose: 1,
            todayBtn: 1
        });

        //富文本插件
        CKEDITOR.replace('input-description');


        //上传文件
        var url = '{:url("product/upload")}';
        $('#fileupload').fileupload({
            url:url,
            dataType:'json',
            done: function (e, data){
                if(!data.result.error){
                    $("#label-file-error").text("").hide();
                    $("#input-image").val(data.result.image);
                    $("#input-image_thumb").val(data.result.image_thumb);
                }
                else{
                    $("#label-file-error").text(data.result.error).show();
                }


            }
        });


    });
</script>
{/block}
{block name="appendCss"}
<!--日历插件-->
<link rel="stylesheet" href="__STATIC__/datetimepicker/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="__STATIC__/jqueryFileUpload/css/jquery.fileupload.css">
{/block}

{block name="appendJs"}
<script src="__STATIC__/datetimepicker/moment.js"></script>
<script src="__STATIC__/datetimepicker/bootstrap-datetimepicker.min.js"></script>

<!--富文本插件-->
<script src="__STATIC__/ckeditor/ckeditor.js"></script>
<script src="__STATIC__/ckeditor/config.js"></script>

<!--文件上传插件-->
<script src="__STATIC__/jqueryFileUpload/js/vendor/jquery.ui.widget.js"></script>
<script src="__STATIC__/jqueryFileUpload/js/jquery.iframe-transport.js"></script>
<script src="__STATIC__/jqueryFileUpload/js/jquery.fileupload.js"></script>
{/block}